package com.polaris.live.adapter

import com.blankj.utilcode.util.StringUtils
import com.polaris.live.R
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.databinding.ItemDaysBinding
import com.polaris.live.resp.bean.DaysBean
import com.polaris.live.translation.R.string

/**
 * DaysAdapter
 *
 * @author Created by 天晴 on 2024/7/17/015 17:13
 */
class DaysAdapter : BaseBindingAdapter<ItemDaysBinding, DaysBean>() {
    private var mSelectIndex = -1
    private var mPayType: Int = -1

    override fun convert(
        holder: VBViewHolder<ItemDaysBinding>,
        item: DaysBean,
    ) {
        holder.vb.apply {
            val position = holder.absoluteAdapterPosition
            if (position == mSelectIndex) {
                daysTv.setBackgroundResource(R.drawable.back_pack_select_back)
            } else {
                daysTv.setBackgroundResource(R.drawable.r8_back_f8f9fa)
            }

            if (item.days == -1) {
                daysTv.text = StringUtils.getString(string.permanent)
            } else {
                daysTv.text = "${item.days}${StringUtils.getString(string.one_days)}"
            }
            if (mPayType == 0) {
                if (item.diamond == null) {
                    root.alpha = 0.5f
                    root.isClickable = false
                } else {
                    root.alpha = 1f
                    root.isClickable = true
                }
            } else {
                if (item.gameCoins == null) {
                    root.alpha = 0.5f
                    root.isClickable = false
                } else {
                    root.alpha = 1f
                    root.isClickable = true
                }
            }


        }
    }

    fun setPayType(type: Int) {
        mPayType = type
        notifyDataSetChanged()
    }

    fun setSelect(position: Int) {
        notifyItemChanged(mSelectIndex)
        mSelectIndex = position
        notifyItemChanged(mSelectIndex)
    }

    fun getSelectData(): DaysBean? {

        return data.getOrNull(mSelectIndex)
    }
}

